home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / C⁄C++ OS8 / Everything / Buttons.cp < prev    next >
Encoding:
Text File  |  1998-09-06  |  9.6 KB  |  456 lines  |  [TEXT/CWIE]

  1. // Buttons.cp
  2.  
  3. #include <Types.h>
  4. #include <Quickdraw.h>
  5. #include <Controls.h>
  6. #include <Dialogs.h>
  7. #include <Events.h>
  8. #include <Lists.h>
  9. #include <Menus.h>
  10. #include <Resources.h>
  11. #include <Sound.h>
  12. #include <TextEdit.h>
  13. #include <ToolUtils.h>
  14. #include <Appearance.h>
  15.  
  16. #include "Globals.h"
  17. #include "ResourceDefs.h"
  18. #include "DoScrap.h"
  19. #include "Miscellany.h"
  20. #include "Scrolling.h"
  21. #include "ControlUtils.h"
  22. #include "DDocData.h"
  23. #include "EverythingEngine.h"
  24. #include "EverythingDoc.h"
  25.  
  26. #include "Buttons.h"
  27.  
  28.  
  29. //----------
  30. void    Buttons::Create (
  31.     AMDoc*            inDoc,
  32.     DDocData*        inData)
  33. {
  34.     Buttons*        winObj = new Buttons;
  35.  
  36.     if (winObj != nil) {
  37.         winObj->Open (inDoc);
  38.         winObj->ConnectToData (inData);
  39.     }
  40. }
  41.  
  42. //----------
  43. Buttons::Buttons ()
  44. {
  45.     mData = nil;
  46. }
  47.  
  48. //----------
  49. Buttons::~Buttons ()
  50. {
  51. }
  52.  
  53. //----------
  54. EverythingEngine*    Buttons::GetEngine ()
  55. {
  56.     return (EverythingEngine*) mDoc->mEngine;
  57. }
  58.  
  59. //----------
  60. void    Buttons::Open (
  61.     AMDoc*            inDoc)
  62. {
  63.     WindowPtr        window;
  64.     Handle            wftb;
  65.  
  66.     mDoc = inDoc;
  67.  
  68.     window = GetNewCWindow (WIND_Buttons, nil, (WindowPtr) -1L);
  69.     if (mDoc->mEngine->GetFilename () [0] != 0) {
  70.         SetWTitle (window, mDoc->mEngine->GetFilename ());
  71.     }
  72.     mWindow = window;
  73.     ((EverythingDoc*)mDoc)->mButtonsPtr = window;
  74.  
  75.     SetWindowKind (window, 'AM');
  76.     SetWRefCon (window, (long) this);
  77.     SetPort (window);
  78.     SetInfo (window);
  79.  
  80.     wftb = ::GetResource ('Wftb', WIND_Buttons);
  81.  
  82.     CreateRootControl (window, &mRootControl);
  83.  
  84.     vScroll = nil;
  85.     hScroll = nil;
  86.  
  87.  
  88.     mCapInvisibleLabel = GetNewControl (CNTL_CapInvisible, window);
  89.     SetWindowItemFont (mCapInvisibleLabel, wftb, 1);
  90.     SetControlFromTEXT (mCapInvisibleLabel, TEXT_CapInvisible);
  91.  
  92.     mInvisibleHandle = ::GetNewControl (CNTL_Invisible, window);
  93.     SetWindowItemFont (mInvisibleHandle, wftb, 2);
  94.  
  95.     mStandardHandle = ::GetNewControl (CNTL_Standard, window);
  96.     SetWindowItemFont (mStandardHandle, wftb, 3);
  97.  
  98.     mDefaultHandle = ::GetNewControl (CNTL_Default, window);
  99.     SetWindowItemFont (mDefaultHandle, wftb, 4);
  100.     SetDefaultState (mDefaultHandle, true);
  101.  
  102.  
  103.     mBevelHandle = ::GetNewControl (CNTL_Bevel, window);
  104.     SetWindowItemFont (mBevelHandle, wftb, 5);
  105.  
  106.     mButtonHandle = ::GetNewControl (CNTL_Button, window);
  107.     EmbedControl (mButtonHandle, mBevelHandle);
  108.     SetWindowItemFont (mButtonHandle, wftb, 6);
  109.     SetBevelButtonGraphicAlignment (mButtonHandle, kControlBevelButtonAlignCenter, 0, 0);
  110.  
  111.     mNextHandle = ::GetNewControl (CNTL_Next, window);
  112.     EmbedControl (mNextHandle, mBevelHandle);
  113.     SetWindowItemFont (mNextHandle, wftb, 7);
  114.     SetBevelButtonTextPlacement (mNextHandle, kControlBevelButtonPlaceToRightOfGraphic);
  115.     SetBevelButtonTextAlignment (mNextHandle, kControlBevelButtonAlignTextFlushLeft, 0);
  116.     SetBevelButtonGraphicAlignment (mNextHandle, kControlBevelButtonAlignLeft, 0, 0);
  117.  
  118.     mNext2Handle = ::GetNewControl (CNTL_Next2, window);
  119.     EmbedControl (mNext2Handle, mBevelHandle);
  120.     SetWindowItemFont (mNext2Handle, wftb, 8);
  121.     SetBevelButtonTextPlacement (mNext2Handle, kControlBevelButtonPlaceBelowGraphic);
  122.     SetBevelButtonTextAlignment (mNext2Handle, kControlBevelButtonAlignTextCenter, 0);
  123.     SetBevelButtonGraphicAlignment (mNext2Handle, kControlBevelButtonAlignTop, 0, 0);
  124.  
  125.  
  126.     mGraphicHandle = ::GetNewControl (CNTL_Graphic, window);
  127.     SetWindowItemFont (mGraphicHandle, wftb, 9);
  128.  
  129.     mCapcicnLabel = GetNewControl (CNTL_Capcicn, window);
  130.     EmbedControl (mCapcicnLabel, mGraphicHandle);
  131.     SetWindowItemFont (mCapcicnLabel, wftb, 10);
  132.     SetControlFromTEXT (mCapcicnLabel, TEXT_Capcicn);
  133.  
  134.     mRightHandle = ::GetNewControl (CNTL_Right, window);
  135.     EmbedControl (mRightHandle, mGraphicHandle);
  136.     SetWindowItemFont (mRightHandle, wftb, 11);
  137.  
  138.     mCapicl8Label = GetNewControl (CNTL_Capicl8, window);
  139.     EmbedControl (mCapicl8Label, mGraphicHandle);
  140.     SetWindowItemFont (mCapicl8Label, wftb, 12);
  141.     SetControlFromTEXT (mCapicl8Label, TEXT_Capicl8);
  142.  
  143.     mLightHandle = ::GetNewControl (CNTL_Light, window);
  144.     EmbedControl (mLightHandle, mGraphicHandle);
  145.     SetWindowItemFont (mLightHandle, wftb, 13);
  146.  
  147.     mCapICNLabel = GetNewControl (CNTL_CapICN, window);
  148.     EmbedControl (mCapICNLabel, mGraphicHandle);
  149.     SetWindowItemFont (mCapICNLabel, wftb, 14);
  150.     SetControlFromTEXT (mCapICNLabel, TEXT_CapICN);
  151.  
  152.     mRight2Handle = ::GetNewControl (CNTL_Right2, window);
  153.     EmbedControl (mRight2Handle, mGraphicHandle);
  154.     SetWindowItemFont (mRight2Handle, wftb, 15);
  155.  
  156.     mCapicl9Label = GetNewControl (CNTL_Capicl9, window);
  157.     EmbedControl (mCapicl9Label, mGraphicHandle);
  158.     SetWindowItemFont (mCapicl9Label, wftb, 16);
  159.     SetControlFromTEXT (mCapicl9Label, TEXT_Capicl9);
  160.  
  161.     mButton2Handle = ::GetNewControl (CNTL_Button2, window);
  162.     EmbedControl (mButton2Handle, mGraphicHandle);
  163.     SetWindowItemFont (mButton2Handle, wftb, 17);
  164.  
  165.     mRight3Handle = ::GetNewControl (CNTL_Right3, window);
  166.     EmbedControl (mRight3Handle, mGraphicHandle);
  167.     SetWindowItemFont (mRight3Handle, wftb, 18);
  168.  
  169.     mCapPICTLabel = GetNewControl (CNTL_CapPICT, window);
  170.     EmbedControl (mCapPICTLabel, mGraphicHandle);
  171.     SetWindowItemFont (mCapPICTLabel, wftb, 19);
  172.     SetControlFromTEXT (mCapPICTLabel, TEXT_CapPICT);
  173.  
  174.     mRect3DHandle = ::GetNewControl (CNTL_Rect3D, window);
  175.     SetWindowItemFont (mRect3DHandle, wftb, 20);
  176.  
  177.     mLeftIconHandle = ::GetNewControl (CNTL_LeftIcon, window);
  178.     SetWindowItemFont (mLeftIconHandle, wftb, 21);
  179.  
  180.     mRightIconHandle = ::GetNewControl (CNTL_RightIcon, window);
  181.     SetWindowItemFont (mRightIconHandle, wftb, 22);
  182.  
  183.     mTitledPICTHandle = ::GetNewControl (CNTL_TitledPICT, window);
  184.     SetWindowItemFont (mTitledPICTHandle, wftb, 23);
  185.  
  186.     AdvanceKeyboardFocus (window);
  187.  
  188.     ShowWindow (window);
  189. }
  190.  
  191. //----------
  192. void    Buttons::Close ()
  193. {
  194.     mData->RemoveResponder (this);
  195.  
  196.     ((EverythingDoc*)mDoc)->mButtonsPtr = nil;
  197.     SetInfo (nil);
  198.     HideWindow (mWindow);
  199.     DisposeWindow (mWindow);
  200.  
  201.     delete this;
  202. }
  203.  
  204. //----------
  205. void    Buttons::ConnectToData (
  206.     DDocData*        inData)
  207. {
  208.     mData = inData;
  209.     mData->AddResponder (this);
  210.  
  211. }
  212.  
  213. //----------
  214. void    Buttons::DataChanged (
  215.     long        inDataID)
  216. {
  217. }
  218.  
  219. //----------
  220. void    Buttons::Control (
  221.     ControlHandle        whichControl,
  222.     short                whichPart,
  223.     Point                where)
  224. {
  225.     Rect            bounds;
  226.     short            newValue;
  227.  
  228.     ExitCurField ();
  229.  
  230.     if (whichControl == mInvisibleHandle) {
  231.         if (TrackClick (mInvisibleHandle, where)) {
  232.         }
  233.     }
  234.     if (whichControl == mStandardHandle) {
  235.         if (TrackClick (mStandardHandle, where)) {
  236.         }
  237.     }
  238.     if (whichControl == mDefaultHandle) {
  239.         if (TrackClick (mDefaultHandle, where)) {
  240.         }
  241.     }
  242.     if (whichControl == mButtonHandle) {
  243.         if (TrackClick (mButtonHandle, where)) {
  244.         }
  245.     }
  246.     if (whichControl == mNextHandle) {
  247.         if (TrackClick (mNextHandle, where)) {
  248.         }
  249.     }
  250.     if (whichControl == mNext2Handle) {
  251.         if (TrackClick (mNext2Handle, where)) {
  252.         }
  253.     }
  254.     if (whichControl == mRightHandle) {
  255.         if (TrackClick (mRightHandle, where)) {
  256.         }
  257.     }
  258.     if (whichControl == mLightHandle) {
  259.         if (TrackClick (mLightHandle, where)) {
  260.         }
  261.     }
  262.     if (whichControl == mRight2Handle) {
  263.         if (TrackClick (mRight2Handle, where)) {
  264.         }
  265.     }
  266.     if (whichControl == mButton2Handle) {
  267.         if (TrackClick (mButton2Handle, where)) {
  268.         }
  269.     }
  270.     if (whichControl == mRight3Handle) {
  271.         if (TrackClick (mRight3Handle, where)) {
  272.         }
  273.     }
  274.     if (whichControl == mRect3DHandle) {
  275.         if (TrackClick (mRect3DHandle, where)) {
  276.         }
  277.     }
  278.     if (whichControl == mLeftIconHandle) {
  279.         if (TrackClick (mLeftIconHandle, where)) {
  280.         }
  281.     }
  282.     if (whichControl == mRightIconHandle) {
  283.         if (TrackClick (mRightIconHandle, where)) {
  284.         }
  285.     }
  286.     if (whichControl == mTitledPICTHandle) {
  287.         if (TrackClick (mTitledPICTHandle, where)) {
  288.         }
  289.     }
  290. }
  291.  
  292. //----------
  293. void    Buttons::MouseIn (
  294.     Point        where,
  295.     short        modifiers)
  296. {
  297.     Rect        bounds;
  298.  
  299. }
  300.  
  301. //----------
  302. void    Buttons::ExitCurField ()
  303. {
  304.     ControlHandle    focus;
  305.  
  306.     GetKeyboardFocus (mWindow, &focus);
  307.  
  308.     if (focus == nil) {
  309.         // nothing to exit
  310.  
  311.     }
  312. }
  313.  
  314. //----------
  315. void    Buttons::TypeIn (
  316.     char        ch)
  317. {
  318.     ControlHandle    focus;
  319.     SInt16            keyCode;
  320.  
  321.     GetKeyboardFocus (mWindow, &focus);
  322.  
  323.     if ((ch == charEnter)
  324.     ||  (ch == charReturn)) {
  325.         ExitCurField ();
  326.         SimulateClick (mDefaultHandle);
  327.     } else if (ch == charEsc) {
  328.     } else if (ch == charTab) {
  329.         DoTab ((curEvent.modifiers & optionKey) != 0);
  330.     } else if (focus != nil) {
  331.         keyCode = (SInt16)(curEvent.message & keyCodeMask);
  332.         HandleControlKey (focus, keyCode, ch, (SInt16)curEvent.modifiers);
  333.         mDoc->mEngine->SetDirty ();
  334.     } else {
  335.         SysBeep (1);
  336.     }
  337. }
  338.  
  339. //----------
  340. void    Buttons::Resize ()
  341. {
  342.     /* application-specific code to resize items in window */
  343. }
  344.  
  345. //----------
  346. void    Buttons::Scroll (
  347.     short        newValue,
  348.     short        oldValue)
  349. {
  350.     /* application-specific code to scroll window */
  351.     if (gWhichScroll == vScroll) {
  352.     } else {    // horizontal
  353.     }
  354. }
  355.  
  356. //----------
  357. void    Buttons::DoUndo ()
  358. {
  359. } // DoUndo
  360.  
  361. //----------
  362. void    Buttons::DoCut ()
  363. {
  364.     TEHandle        curTE = GetCurTE ();
  365.  
  366.     if (curTE != nil) {
  367.         TECut (curTE);
  368.         mDoc->mEngine->SetDirty ();
  369.         scrapDirty = true;
  370.     }
  371. } // DoCut
  372.  
  373. //----------
  374. void    Buttons::DoCopy ()
  375. {
  376.     TEHandle        curTE = GetCurTE ();
  377.  
  378.     if (curTE != nil) {
  379.         TECopy (curTE);
  380.         scrapDirty = true;
  381.     }
  382. } // DoCopy
  383.  
  384. //----------
  385. void    Buttons::DoPaste ()
  386. {
  387.     TEHandle        curTE = GetCurTE ();
  388.  
  389.     if (curTE != nil) {
  390.         TEPaste (curTE);
  391.         mDoc->mEngine->SetDirty ();
  392.     }
  393. } // DoPaste
  394.  
  395. //----------
  396. void    Buttons::DoClear ()
  397. {
  398.     TEHandle        curTE = GetCurTE ();
  399.  
  400.     if (curTE != nil) {
  401.         TEDelete (curTE);
  402.         mDoc->mEngine->SetDirty ();
  403.     }
  404. } // DoClear
  405.  
  406. //----------
  407. void    Buttons::DoSelectAll ()
  408. {
  409.     TEHandle        curTE = GetCurTE ();
  410.  
  411.     if (curTE != nil) {
  412.         TESetSelect (0, 32767, curTE);
  413.     }
  414. } // DoSelectAll
  415.  
  416. //----------
  417. void    Buttons::DoShowClipboard ()
  418. {
  419. } // DoShowClipboard
  420.  
  421. //----------
  422. Boolean        Buttons::DoCommand (
  423.     long        inCommand)
  424. {
  425.     Boolean        result = true;
  426.  
  427.     switch (inCommand) {
  428.         case cmdUndo:
  429.                 DoUndo ();
  430.             break;
  431.         case cmdCut:
  432.                 DoCut ();
  433.             break;
  434.         case cmdCopy:
  435.                 DoCopy ();
  436.             break;
  437.         case cmdPaste:
  438.                 DoPaste ();
  439.             break;
  440.         case cmdClear:
  441.                 DoClear ();
  442.             break;
  443.         case cmdSelectAll:
  444.                 DoSelectAll ();
  445.             break;
  446.         case cmdShowClipboard:
  447.                 DoShowClipboard ();
  448.             break;
  449.  
  450.         default:
  451.                 result = false;
  452.     } // switch
  453.  
  454.     return result;
  455. }
  456.